package com.yunji.common.model.domain;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.yunji.common.annotation.Excel;
import com.yunji.common.annotation.Excel.ColumnType;
import com.yunji.common.annotation.Excel.Type;
import com.yunji.common.annotation.Excels;
import com.yunji.common.base.RuoYiBaseEntity;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.EqualsAndHashCode;

import java.io.Serializable;
import java.math.BigDecimal;
import java.util.Arrays;
import java.util.Date;
import java.util.List;

;

/**
 * 用户对象 sys_user
 *
 * @author yunji
 */
@EqualsAndHashCode(callSuper = true)
@Data
public class SysUserDO extends RuoYiBaseEntity implements Serializable {
    private static final long serialVersionUID = 1L;

    /**
     * 用户ID
     */
    @ApiModelProperty("用户序号")
    @Excel(name = "用户序号", cellType = ColumnType.NUMERIC, prompt = "用户编号")
    private Long userId;

    /**
     * 所属单位ID
     */
    @ApiModelProperty("所属信息ID")
    @Excel(name = "所属信息ID", width = 15)
    private Long belongId;

    @ApiModelProperty("所属名称")
    private String belongName;

    @ApiModelProperty("归属信息ID")
    @Excel(name = "归属信息ID", width = 15)
    private Long parentId;

    /**
     * 是否为组长
     */
    @ApiModelProperty("主账户(0:否;1:是;)")
    @Excel(name = "主账户(0:否;1:是;)")
    private Integer mainAccount;

    /**
     * 部门ID
     */
    @ApiModelProperty("部门编号")
    @Excel(name = "部门编号", type = Type.IMPORT)
    private Long deptId;

    /**
     * 用户账号
     */
    @ApiModelProperty("登录名称")
    @Excel(name = "登录名称")
    private String userName;

    /**
     * 用户昵称
     */
    @ApiModelProperty("用户名称")
    @Excel(name = "用户名称")
    private String nickName;

    @ApiModelProperty("用户类型 ('00'管理员 '01'测试 '02'代理商)")
    @Excel(name = "用户类型")
    private String userType;

    /**
     * 用户邮箱
     */
    @ApiModelProperty("用户邮箱")
    @Excel(name = "用户邮箱")
    private String email;

    /**
     * 手机号码
     */
    @ApiModelProperty("手机号码")
    @Excel(name = "手机号码", cellType = ColumnType.TEXT)
    private String phonenumber;

    /**
     * 用户性别
     */
    @ApiModelProperty("用户性别")
    @Excel(name = "用户性别", readConverterExp = "0=男,1=女,2=未知")
    private String sex;

    /**
     * 用户头像
     */
    @ApiModelProperty("用户头像")
    private String avatar;

    private String delFlag;

    /**
     * 密码
     */
    @ApiModelProperty("密码")
    private String password;

    /**
     * 帐号状态（0正常 1停用）
     */
    @ApiModelProperty("账号状态 (0-正常 1-停用)")
    @Excel(name = "帐号状态", readConverterExp = "0=正常,1=停用")
    private String status;

    /**
     * 最后登录IP
     */
    @ApiModelProperty("最后登录IP")
    @Excel(name = "最后登录IP", type = Type.EXPORT)
    private String loginIp;

    /**
     * 最后登录时间
     */
    @ApiModelProperty("最后登陆时间")
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    @Excel(name = "最后登录时间", width = 30, dateFormat = "yyyy-MM-dd HH:mm:ss", type = Type.EXPORT)
    private Date loginDate;

    /**
     * 省份代码
     */
    @ApiModelProperty("省份代码")
    @Excel(name = "省份代码")
    private String provinceCode;

    /**
     * 省份名称
     */
    @ApiModelProperty("省份名称")
    @Excel(name = "省份名称")
    private String provinceName;

    /**
     * 城市代码
     */
    @ApiModelProperty("城市代码")
    @Excel(name = "城市代码")
    private String cityCode;

    /**
     * 城市名称
     */
    @ApiModelProperty("城市名称")
    @Excel(name = "城市名称")
    private String cityName;

    /**
     * 城市名称
     */
    @ApiModelProperty("城市名称")
    @Excel(name = "城市名称")
    private String countyCode;

    /**
     * 城市名称
     */
    @ApiModelProperty("城市名称")
    @Excel(name = "城市名称")
    private String countyName;

    /**
     * 地区信息
     */
    @ApiModelProperty("地区信息")
    @Excel(name = "地区信息")
    private String region;

    /**
     * 出生时间
     */
    @ApiModelProperty("出生时间")
    @Excel(name = "出生时间")
    private Date birthTime;

    /**
     * 详细地址
     */
    @ApiModelProperty("详细地址")
    @Excel(name = "详细地址")
    private Date address;

    /**
     * 累计收益
     */
    @ApiModelProperty("累计收益")
    @Excel(name = "累计收益")
    private BigDecimal earnAmount;

    /**
     * 提现金额
     */
    @ApiModelProperty("提现金额")
    @Excel(name = "提现金额")
    private BigDecimal cashAmount;

    /**
     * 账户余额
     */
    @ApiModelProperty("账户余额")
    @Excel(name = "账户余额")
    private BigDecimal remainAmount;

    /**
     * 冻结金额
     */
    @ApiModelProperty("冻结金额")
    @Excel(name = "冻结金额")
    private BigDecimal frozenAmount;

    @ApiModelProperty("退款金额")
    @Excel(name = "退款金额")
    private BigDecimal refundAmount;

    /**
     * 用户端openid
     */
    @Excel(name = "用户端openid")
    @ApiModelProperty("用户端openid")
    private String openid;

    /**
     * 年龄标签
     */
    @Excel(name = "年龄标签")
    @ApiModelProperty("年龄标签")
    private String ageLabel;

    /**
     * 星座标签
     */
    @Excel(name = "星座标签")
    @ApiModelProperty("星座标签")
    private String constellationLabel;

    /**
     * 职业标签
     */
    @Excel(name = "职业标签")
    @ApiModelProperty("职业标签")
    private String careerLabel;

    /**
     * 社交现状标签
     */
    @Excel(name = "社交现状标签")
    @ApiModelProperty("社交现状标签")
    private String socialLabel;

    @Excel(name = "代理商ID")
    @ApiModelProperty("代理商ID")
    private Long agentId;

    @Excel(name = "代理商名称")
    @ApiModelProperty("代理商名称")
    private String agentName;

    @Excel(name = "分成类型 0-不分成 1-按交易金额 2-按交易笔数")
    @ApiModelProperty("分成类型 0-不分成 1-按交易金额 2-按交易笔数")
    private Integer scaleType;

    @Excel(name = "分成比例/每笔金额")
    @ApiModelProperty("分成比例/每笔金额")
    private BigDecimal scale;

    private Long roleId;
    /**
     * 部门对象
     */
    @ApiModelProperty("部门对象")
    @Excels({
            @Excel(name = "部门名称", targetAttr = "deptName", type = Type.EXPORT),
            @Excel(name = "部门负责人", targetAttr = "leader", type = Type.EXPORT)
    })
    private SysDeptDO dept;

    /**
     * 角色对象
     */
    @ApiModelProperty("角色对象")
    private List<SysRoleDO> roles;

    /**
     * 角色组
     */
    @ApiModelProperty("角色组")
    private Long[] roleIds;

    /**
     * 岗位组
     */
    @ApiModelProperty(value = "岗位组", hidden = true)
    private Long[] postIds;

    public SysUserDO() {
    }

    public SysUserDO(Long userId) {
    }

    public void setRoleIds(Long... roleIds) {
        this.roleIds = roleIds;
    }

    @Override
    public String toString() {
        return "SysUser{" +
                "userId=" + userId +
                ", deptId=" + deptId +
                ", userName='" + userName + '\'' +
                ", nickName='" + nickName + '\'' +
                ", userType='" + userType + '\'' +
                ", email='" + email + '\'' +
                ", phonenumber='" + phonenumber + '\'' +
                ", sex='" + sex + '\'' +
                ", avatar='" + avatar + '\'' +
                ", password='" + password + '\'' +
                ", status='" + status + '\'' +
                ", loginIp='" + loginIp + '\'' +
                ", loginDate=" + loginDate +
                ", provinceCode='" + provinceCode + '\'' +
                ", provinceName='" + provinceName + '\'' +
                ", cityCode='" + cityCode + '\'' +
                ", cityName='" + cityName + '\'' +
                ", countyCode='" + countyCode + '\'' +
                ", countyName='" + countyName + '\'' +
                ", region='" + region + '\'' +
                ", birthTime=" + birthTime +
                ", address=" + address +
                ", earnAmount=" + earnAmount +
                ", cashAmount=" + cashAmount +
                ", remainAmount=" + remainAmount +
                ", frozenAmount=" + frozenAmount +
                ", refundAmount=" + refundAmount +
                ", openid='" + openid + '\'' +
                ", ageLabel='" + ageLabel + '\'' +
                ", constellationLabel='" + constellationLabel + '\'' +
                ", careerLabel='" + careerLabel + '\'' +
                ", socialLabel='" + socialLabel + '\'' +
                ", agentId=" + agentId +
                ", agentName='" + agentName + '\'' +
                ", scaleType=" + scaleType +
                ", scale=" + scale +
                ", dept=" + dept +
                ", roles=" + roles +
                ", roleIds=" + Arrays.toString(roleIds) +
                ", postIds=" + Arrays.toString(postIds) +
                ", roleId=" + roleId + '}';
    }

    public boolean isAdmin() {
        return isAdmin(this.userId);
    }


    public static boolean isAdmin(Long userId) {
        return userId != null && 1L == userId;
    }

}
